<template>
	<view class="cart-container">
		<!-- 收货地址 -->
		<my-address></my-address>
		<!-- 商品列表标题 -->
		<view class="goodsList-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text>购物车</text>
		</view>
		<uni-swipe-action class="goodsList-container">
			<block v-for="(goods, i) in cart" :key="i">
				<uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(goods)">
					<my-goods :goods="goods" :showRadio="true" @radio-change="radioChangeHandler" @numChange="numChangeHandler"></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<!-- 结算区域 -->
		<my-settle></my-settle>
	</view>
</template>

<script>
	import tabbarBadge from '@/mixins/tabbar-badge.js'
	import { mapState, mapMutations } from 'vuex'
	export default {
		data() {
			return {
					options: [{
					text: '删除', // 显示的文本内容
					style: {
						backgroundColor: '#C00000' // 按钮的背景颜色
					}
				}]
			};
		},
		mixins: [tabbarBadge],
		computed: {
			...mapState('m_cart', ['cart'])
		},
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'removeGoodsByID']),
			radioChangeHandler(val) {
				this.updateGoodsState(val)
			},
			numChangeHandler(val) {
				this.updateGoodsCount(val)
			},
			swipeActionClickHandler(goods) {
			  this.removeGoodsByID(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.cart-container {
		padding-bottom: 50px;
	}
	.goodsList-title {
		height: 40px;
		display: flex;
		gap: 10px;
		align-items: center;
		font-size: 14px;
		padding-left: 5px;
		border-bottom: 1px solid #efefef;
		
	}
</style>
